# -*- coding: utf-8 -*-
#Constantes

#Podemos importar todos os modulos que serão usados por mais de um arquivo aqui
# visto que todos os arquivos usará este.
import sys, math, os
from pygame import image, display, font, event, transform
from pygame.locals import *
from pygame.sprite import Sprite, Group, groupcollide, spritecollide

# Largura e Algura da Janela principal
WIDTH, HEIGHT = 1260, 700

# Janela principal do jogo.
SCREEN = display.set_mode((WIDTH, HEIGHT), SRCALPHA)

# Iniciar os modulos necessários
font.init()

DIRECTORY = os.path.abspath(os.curdir)
DATA = DIRECTORY + '/data'
IMAGE = DATA + '/images'

class ImageData:
    def __init__(self, image, animated=False, size = (0,0), offset = 0, lifespan=-1):
        self.image = image
        self.animated = animated
        self.size = size
        self.offset = offset
        self.lifespan = lifespan

    def get_size(self):
        return self.size

    def get_image(self):
        return self.image

    def get_offset(self):
        return self.offset

    def is_animated(self):
        return self.animated

    def get_lifespan(self):
        return self.lifespan

def parse_enemy_data(data):
    image_data = ImageData(image.load(IMAGE +"/"+data[0]).convert_alpha())
    acc = eval("[%s,%s]" %(data[1],data[2]))
    typ = eval(data[3])
    return (image_data, acc, typ)

def load_enemy(file_uri):
    enemy_data = {}
    with open(file_uri) as f:
        f.readline()
        for line in f:
            line = line.split()
            enemy_data[eval(line[0])] = parse_enemy_data(line[1:])
    return enemy_data

ENEMYS = load_enemy(DATA + "/enemy.dat")
            
def parse_stage_data(data):
    background = eval(data[0])
    enemys = eval(data[1])  
    boss = eval(data[2])
    return (background, enemys, boss)

def load_stage(file_uri):
    stage_data = {}
    with open(file_uri) as f:
        f.readline()
        for line in f:
            line = line.split()
            stage_data[eval(line[0])] = parse_stage_data(line[1:])
    return stage_data


STAGES = load_stage(DATA + "/stage.dat")

# imagem do player
PLAYER_IMAGE = ImageData(image.load(IMAGE +"/player.png").convert_alpha())
                         
PLAYER_IMAGE_R = ImageData(image.load(IMAGE + "/playerToRight.png").convert_alpha())
PLAYER_IMAGE_L = ImageData(image.load(IMAGE +"/playerToLeft.png").convert_alpha())

#carrega a imagem do tiro
SHOT_IMAGE = ImageData(image.load(IMAGE + "/nanobeast.png").convert_alpha())

EXPLOSION = ImageData(image.load(IMAGE + "/explosion.png").convert_alpha(),
                      True, (100,100), 100, 78)
#Cores
BLACK = (0,0,0)
